package com.bite.system.controller.question;

import com.bite.common.core.controller.BaseController;
import com.bite.common.core.domain.R;
import com.bite.common.core.domain.TableDataInfo;
import com.bite.system.domain.question.dto.QuestionAddDTO;
import com.bite.system.domain.question.dto.QuestionQueryDTO;
import com.bite.system.domain.question.vo.QuestionDetailVO;
import com.bite.system.domain.question.vo.QuestionVO;
import com.bite.system.domain.question.dto.QuestionEditDTO;
import com.bite.system.service.question.IQuestionService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RequestMapping("/question")
@RestController
@Tag(name = "题目管理接口")
public class QuestionController extends BaseController {


    @Autowired
    private IQuestionService questionService;


    /**
     * 题库列表
     * @param questionQueryDTO
     * @return
     */
    @GetMapping("/list")
    //返回的一堆,泛型可以是题目列表
    //还有展示题目总条数,分页相关信息-改动R
    public TableDataInfo list(QuestionQueryDTO questionQueryDTO){
        List<QuestionVO> questionVOList = questionService.list(questionQueryDTO);
        return getTableDataInfo(questionVOList);
    }


    /**
     * 新增题库
     * @param questionAddDTO
     * @return
     */
    @PostMapping("/add")
    public R<Void> add(@RequestBody QuestionAddDTO questionAddDTO){
        return toR(questionService.add(questionAddDTO));

    }


    /**
     * 查询题目信息
     * @param questionId
     * @return
     */
    @GetMapping("/detail")
    public R<QuestionDetailVO> detail(Long questionId){
        return R.ok(questionService.detail(questionId));
    }


    /**
     * 编辑
     * @param questionEditDTO
     * @return
     */
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody QuestionEditDTO questionEditDTO){
        return toR(questionService.edit(questionEditDTO));
    }


    /**
     * 删除题目
     * @param questionId
     * @return
     */
    @DeleteMapping("/delete")
    public R<Void> delete(Long questionId){
        return toR(questionService.delete(questionId));
    }
}
